package com.ruoyi.web.controller.water;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.waterEnity.BuildingEntity;
import com.ruoyi.system.domain.waterEnity.DistributionInfoBo;
import com.ruoyi.system.service.waterService.DistributionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/water")
public class DistributionController extends BaseController {
    @Autowired
    private DistributionService distributionService;

    /**
     * 跳转到配送页面
     */
    @RequiresPermissions("water:distribution:view")
    @GetMapping("/distribution")
    public String distribution(ModelMap map){
        List<BuildingEntity> buildingEntities = distributionService.selectBuilding();
        map.put("building",buildingEntities);
        return "water/distribution/distribution";
    }
    /**
     * 配送列表
     *
     * @return
     */
    @RequiresPermissions("water:distribution:view")
    @PostMapping("/distributionList")
    @ResponseBody
    public TableDataInfo distributionList(String phone, String building, String state) {
        startPage();
        List<DistributionInfoBo> list = distributionService.selectAllDistrition(phone,building,state);
        System.out.println(list);
        return getDataTable(list);
    }

    /**
     * 导出配送数据
     * @param ids
     * @return
     */
    @RequiresPermissions("evaluation:store:export")
    @PostMapping("/exportDistribution")
    @ResponseBody
    public AjaxResult exportDistribution(String ids){
        System.out.println("ids================"+ids);
        //加入所选择的参数，可以导出全部或者选定的部分
        List<DistributionInfoBo> list = distributionService.selectOrderByIds(ids);
        ExcelUtil<DistributionInfoBo> util = new ExcelUtil<DistributionInfoBo>(DistributionInfoBo.class);
        return util.exportExcel(list,"导出配送数据");
    }


}
